package web.servlet.worker;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import service.WorkerServiceImpl;
import domain.Worker;

public class WorkerLoginServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//处理表单数据			
		String workerAccount = request.getParameter("workerAccount");
		String workerPassword = request.getParameter("workerPassword");
		//调用业务逻辑
		WorkerServiceImpl ws = new WorkerServiceImpl();
		Worker worker = ws.login(workerAccount, workerPassword);
		//分发转向    //HttpSession会话，
		HttpSession session = request.getSession();
		if(worker!=null){
			session.setAttribute("worker", worker);
			session.setAttribute("massage", "");
			response.sendRedirect("/PetsManagement/admin/login/home.jsp");
		}else{
			session.setAttribute("massage", "登陆失败，用户名或密码错误！请重新登录！");
			response.sendRedirect("/PetsManagement/login.jsp");
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
